package com.xt.back.utils;



import com.xt.back.constant.ResultDTO;
import com.xt.back.exception.OperateException;
import com.xt.back.exception.ParamsException;
import com.xt.back.exception.PermissionsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: 小童
 * @CreateDate: 2021/7/25 0:06
 * @note:全局异常处理
 * @Version: 1.0
 */
@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(Exception.class)
    public ResultDTO handleException(Exception e) {
        e.printStackTrace();
        return ResultDTO.error(e.getMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    public ResultDTO handleRuntimeException(RuntimeException e) {
        e.printStackTrace();
        return ResultDTO.error(e.getMessage());
    }

    @ExceptionHandler(PermissionsException.class)
    public ResultDTO PermissionsException(PermissionsException permissionsException){
        return ResultDTO.failure(permissionsException.getMessage());
    }

    @ExceptionHandler(ParamsException.class)
    public ResultDTO ParamsException(ParamsException paramsException){
        return ResultDTO.error(paramsException.getMessage());
    }

    @ExceptionHandler(OperateException.class)
    public ResultDTO handleNoDataException(OperateException e) {
        return ResultDTO.error(e.getMessage());
    }

}
